import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)

var getUrlKey = function(name){
	return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}

export default new Vuex.Store({
    state: {
	    load: true,
	    url:'http://xsapi.5kb.pw/api.php/',
		device: getUrlKey('device_sn') ? getUrlKey('device_sn'):'000001',
	    searchVal:''
	},
	mutations: {
	    loadSwitch (state,Bool) {
	    	// 变更状态
	    	if( typeof Bool == 'boolean'){
	    		state.load = Bool;
	    	}else{
		        state.load = !state.load;
	    	}
	    },
	    setSearchVal(state,val){
	    	state.searchVal = val;
	    }
	}
});